<template>
    <div style="height:100%;width:100%;position:relative;">
        <div class="pagetop" ref="buttondiv">
            <div class="top-title">新增院感申请将自动增加报告项目和相关对照！</div>
            <div class="top-button">
                <el-button @click="OpenDialog(1)" icon="el-icon-plus" v-has="'PADD'" v-show="editvisible">新增</el-button>
                <el-button @click="OpenDialog(2)" icon="el-icon-edit" v-has="'PMODIFY'" v-show="editvisible">修改</el-button>
                <el-button @click="OpenDialog(3)" icon="el-icon-delete" v-has="'PDELETE'" v-show="editvisible">删除</el-button>
                <el-button @click="OpenReqItemDialog(1)" icon="el-icon-plus" v-has="'POTHER1'" v-show="recordvisible">新增明细</el-button>
                <el-button @click="OpenReqItemDialog(2)" icon="el-icon-edit" v-has="'POTHER2'" v-show="recordvisible">修改明细</el-button>
                <el-button @click="OpenReqItemDialog(3)" icon="el-icon-delete" v-has="'POTHER3'" v-show="recordvisible">删除明细</el-button>
            </div>
        </div>
        <div class="pagecenter">
            <rm-layout-right splitcolor="#ffffff" :splitwidth="3" :fixsize="300" :minfixsize="200" ref="layoutright">
                <div ref="xTableDiv" style="height:100%;">
                    <vxe-table :data="list" 
                        :loading="loading" 
                        :keyboard-config="keyConfig" 
                        :keyboard-local-config="keyLocalConfig" 
                        :select-config="{trigger:'row'}" 
                        :sort-config="{trigger: 'cell'}" 
                        @current-change="currentChangeEvent" 
                        border fit height="auto" 
                        header-align="center" 
                        highlight-current-row 
                        highlight-hover-row 
                        highlight-hover-column 
                        ref="xTable" 
                        resizable 
                        show-header-overflow="tooltip" 
                        show-overflow="tooltip" 
                        size="mini" stripe :row-class-name="rowClassName">
                        <vxe-table-column field="code" title="代号" width="60"></vxe-table-column>
                        <vxe-table-column field="name" title="名称" width="120"></vxe-table-column>
                        <vxe-table-column field="specimencode" title="标本种类" width="80"></vxe-table-column>
                        <vxe-table-column field="cysj" title="采样时间" width="200"></vxe-table-column>
                        <vxe-table-column field="cyff" title="采样方法" width="200"></vxe-table-column>
                        <vxe-table-column field="syff" title="实验方法" width="200"></vxe-table-column>
                        <vxe-table-column field="jsgs" title="计算公式" width="200"></vxe-table-column>
                        <vxe-table-column field="zysx" title="注意事项" width="200"></vxe-table-column>
                        <vxe-table-column field="sortindex" title="顺序号" width="60"></vxe-table-column>
                    </vxe-table>
                </div>
                <template v-slot:fix>
                    <div>
                        <el-tabs @tab-click="handleTabClick" style="height:100%;" type="border-card">
                            <el-tab-pane label="基本信息">
                                <el-form :inline="true" :model="YGKindRight" @submit.native.prevent label-width="auto" ref="form">
                                    <table height="100%" width="100%" style="border-spacing:5px 5px;" class="tablelayout">
                                        <tr>
                                            <td width="100px">代号</td>
                                            <td>
                                                <el-input v-model="YGKindRight.code" readonly></el-input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>名称</td>
                                            <td>
                                                <el-input v-model="YGKindRight.name" readonly></el-input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>标本种类</td>
                                            <td>
                                                <el-input v-model="YGKindRight.specimencode" readonly></el-input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>采样时间</td>
                                            <td>
                                                <el-input type="textarea" v-model="YGKindRight.cysj" maxlength="2000" rows="3"  show-word-limit readonly></el-input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>采样方法</td>
                                            <td>
                                                <el-input type="textarea" v-model="YGKindRight.cyff" maxlength="2000" rows="7" show-word-limit readonly></el-input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>实验方法</td>
                                            <td>
                                                <el-input type="textarea" v-model="YGKindRight.syff" maxlength="2000" rows="4" show-word-limit readonly></el-input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>计算公式</td>
                                            <td>
                                                <el-input type="textarea" v-model="YGKindRight.jsgs" maxlength="2000" rows="4" show-word-limit readonly></el-input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>注意事项</td>
                                            <td>
                                                <el-input type="textarea" v-model="YGKindRight.zysx" maxlength="2000" rows="5" show-word-limit readonly></el-input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>顺序号</td>
                                            <td>
                                                <el-input label="" v-model="YGKindRight.sortindex" readonly></el-input>
                                            </td>
                                        </tr>
                                        
                                    </table>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane v-if="oneBarcode" label="申请项目">
                                <div ref="xTableDiv2" style="height:100%">
                                    <vxe-table :data="tableDataReqItem" 
                                        :loading="loadingReqItem" 
                                        :keyboard-config="keyConfig" 
                                        :keyboard-local-config="keyLocalConfig" 
                                        :select-config="{trigger:'row'}" 
                                        :sort-config="{trigger: 'cell'}" 
                                        @current-change="currentReqItemChangeEvent" 
                                        :row-class-name="rowClassName" 
                                        fit height="auto" 
                                        header-align="center" 
                                        highlight-current-row 
                                        highlight-hover-row 
                                        highlight-hover-column 
                                        ref="xTable2" resizable 
                                        show-header-overflow="tooltip" 
                                        show-overflow="tooltip" 
                                        size="mini" border stripe>
                                        <vxe-table-column field="req_itemcode" key="req_itemcode" title="申请项目代号" width="120px" sortable></vxe-table-column>
                                        <vxe-table-column field="req_itemname" key="req_itemname" title="申请项目名称" width="220px" sortable></vxe-table-column>
                                        <vxe-table-column field="seq" key="seq" title="序号" width="60px" sortable></vxe-table-column>
                                    </vxe-table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </div>
                </template>
            </rm-layout-right>

        </div>
        <!-- top="4vh height="600px"" -->
        <el-dialog v-el-drag-dialog :close-on-click-modal="false" :center="true" :title="dialogTitle" :visible.sync="dialogYGKindFormVisible" width="800px" height="3000px" v-if="dialogYGKindFormVisible">
            <div>
                <el-form :inline="true" :model="YGKind" @submit.native.prevent label-width="auto" ref="form">
                    <table height="100%" width="100%" style="width:100%" class="tablelayout" ref="inputtable">
                        <tr>
                            <td style="color:red">代码：</td>
                            <td>
                                <el-input size="mini" v-model="YGKind.code" ref="autofocus1" @keyup.enter.native="Funautofocus('autofocus1')"></el-input>
                            </td>
                        </tr>
                        <tr>
                            <td style="color:red">名称：</td>
                            <td>
                                <el-input size="mini" v-model="YGKind.name" ref="autofocus2" @keyup.enter.native="Funautofocus('autofocus2')"></el-input>
                            </td>
                        </tr>
                        <tr>
                            <td>标本类型：</td>
                            <td>
                                <rm-ddl-common datatype="specimen" dataname="标本类型" :appendtobody="true" v-model="YGKind.specimencode" ref="autofocus3" @keyup.enter.native="Funautofocus('autofocus3')"></rm-ddl-common>
                            </td>
                        </tr>
                        <tr>
                            <td style="vertical-align:top">采样时间：</td>
                            <td>
                                <el-input type="textarea" v-model="YGKind.cysj" ref="autofocus4" @keyup.enter.native="Funautofocus('autofocus4')" maxlength="2000" show-word-limit></el-input>
                            </td>
                        </tr>
                        <tr>
                            <td style="vertical-align:top">采样方法：</td>
                            <td>
                                <el-input type="textarea" v-model="YGKind.cyff" ref="autofocus5" @keyup.enter.native="Funautofocus('autofocus5')" maxlength="2000" show-word-limit></el-input>
                            </td>
                        </tr>
                        <tr>
                            <td style="vertical-align:top">实验方法：</td>
                            <td>
                                <el-input type="textarea" v-model="YGKind.syff" ref="autofocus6" @keyup.enter.native="Funautofocus('autofocus6')" maxlength="2000" show-word-limit></el-input>
                            </td>
                        </tr>
                        <tr>
                            <td style="vertical-align:top">计算公式：</td>
                            <td>
                                <el-input type="textarea" v-model="YGKind.jsgs" ref="autofocus7" @keyup.enter.native="Funautofocus('autofocus7')" maxlength="2000" show-word-limit></el-input>
                            </td>
                        </tr>
                        <tr>
                            <td style="vertical-align:top">注意事项：</td>
                            <td>
                                <el-input type="textarea" v-model="YGKind.zysx" ref="autofocus8" @keyup.enter.native="Funautofocus('autofocus8')" maxlength="2000" show-word-limit></el-input>
                            </td>
                        </tr>
                        <tr>
                            <td style="color:red">顺序号：</td>
                            <td>
                                <el-input size="mini" v-model="YGKind.sortindex" ref="autofocus9" @keyup.enter.native="Funautofocus('autofocus9')"></el-input>
                            </td>
                        </tr>
                    </table>
                </el-form>
                <div class="dialog-footer" slot="footer" style="text-align:right">
                    <table style="width:100%">
                        <tr>
                            <td width="630"></td>
                            <td>
                                <el-button @click="CommitTips()">确 定</el-button>
                            </td>
                            <td>
                                <el-button @click="CancelTips()">取 消</el-button>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </el-dialog>

        <el-dialog v-el-drag-dialog :close-on-click-modal="false" title="提示" :visible.sync="dialogVisible" width="30%">
            <div class="el-message-box__status el-icon-warning"></div>
            <div class="el-message-box__message" style="padding-top:24px">
                <p>确定要删除院感分类<b style="color:red">{{ DelYGKindName }}</b>吗?</p>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="CommitTips()">确 定</el-button>
                <el-button @click="CancelTips()">取 消</el-button>
            </span>
        </el-dialog>

        <el-dialog v-el-drag-dialog :close-on-click-modal="false" :center="true" :title="dialogReqItemTitle" :visible.sync="dialogFormVisible" width="400px" height="3000px" v-if="dialogFormVisible">
            <div>
                <el-form :inline="true" :model="ReqItem" @submit.native.prevent label-width="auto" ref="form">
                    <table height="100%" width="100%" style="width:100%" class="tablelayout" ref="inputtable">
                        <tr>
                            <td style="color:red">申请项目代码：</td>
                            <td>
                                <el-input size="mini" v-model="ReqItem.req_itemcode" ref="rautofocus1" @keyup.enter.native="Funautofocus('rautofocus1')"></el-input>
                            </td>
                        </tr>
                        <tr>
                            <td style="color:red">申请项目名称：</td>
                            <td>
                                <el-input size="mini" v-model="ReqItem.req_itemname" @input="NameInput" @change="NameChange" ref="rautofocus2" @keyup.enter.native="Funautofocus('rautofocus2')"></el-input>
                            </td>
                        </tr>
                        <tr>
                            <td style="color:red">顺序号：</td>
                            <td>
                                <el-input size="mini" v-model="ReqItem.seq" ref="rautofocus3" @keyup.enter.native="Funautofocus('rautofocus3')"></el-input>
                            </td>
                        </tr>
                    </table>
                </el-form>
                <div class="dialog-footer" slot="footer" style="text-align:right">
                    <table style="width:100%">
                        <tr>
                            <td width="630"></td>
                            <td>
                                <el-button @click="CommitReqItemTips()">确 定</el-button>
                            </td>
                            <td>
                                <el-button @click="CancelReqItemTips()">取 消</el-button>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </el-dialog>

        <el-dialog v-el-drag-dialog :close-on-click-modal="false" title="提示" :visible.sync="dialogReqItemVisible" width="30%">
            <div class="el-message-box__status el-icon-warning"></div>
            <div class="el-message-box__message" style="padding-top:24px">
                <p>确定要删除院感申请项目<b style="color:red">{{ DelReqItemName }}</b>吗?</p>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="CommitReqItemTips()">确 定</el-button>
                <el-button @click="CancelReqItemTips()">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: "MNG238",
    data() {
        return {
            tableData: [],
            YGKindRight: {},
            YGKind: {},
            OldYGKind: {},
            DelYGKindName: "",
            AddArray: "",
            tempRowIndex: 0,
            loading: false,
            FirstLoading: true,
            tableTempData: [],
            dialogTitle: "",
            dialogYGKindFormVisible: false,
            
            dialogVisible: false,
            actionflag: 0,
            curtabindex: 0,
            buttonwidth: "",
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true
            },
            keyLocalConfig: {
                isArrow: true
            },
            editvisible: true,
            recordvisible: false,

            loadingReqItem: false,
            tableDataReqItem: [],
            ReqItem: {},
            ReqItemRow: {},
            OldReqItem: {},
            dialogReqItemTitle:"",
            dialogReqItemVisible:false,
            DelReqItemName: "",
            tempReqItemRowIndex: 0,
            reqItemactionflag: 0,
            dialogFormVisible: false,
            oneBarcode: true,
        };
    },
    computed: {
        list() {
            return this.tableData;
        }
    },
    watch: {
        searchtext(val) {
            var length = this.tableData.length;
            if (this.AddArray != "") {
                this.AddArray = "";
            }
            this.$nextTick(() => {
                var row = this.$refs.xTable.getCurrentRow();
                if (this.$refs.xTable.tableData.length > 0) row = this.$refs.xTable.tableData[0];
                if (row.req_itemcode) {
                    this.$refs.xTable.setCurrentRow(row);
                    this.YGKindRight = row;
                    this.DelYGKindName = row.name;
                    this.tempRowIndex = this.$refs.xTable.getRowIndex(row);
                    if (this.curtabindex == 1) {
                        this.ShowReqItem();
                    }
                }
            });
        }
    },
    created() {
        this.InitPageData();
    },
    mounted() {},
    updated() {
        this.getButtonWidth();
        if (this.FirstLoading) {
            var selectrow = {};
            if (this.AddArray > 0) {
                selectrow = this.$refs.xTable.tableData.filter(item => {
                    return item.req_itemcode == this.AddArray;
                })[0];
            } else {
                if (this.tempRowIndex > 0) selectrow = this.$refs.xTable.getData(this.tempRowIndex);
                else selectrow = this.$refs.xTable.getData(0);
            }
            if (selectrow) {
                this.FirstLoading = false;
                this.$nextTick(() => {
                    this.$refs.xTable.setCurrentRow(selectrow);
                    this.YGKindRight = selectrow;
                    this.DelYGKindName = selectrow.name;
                    this.$refs.xTable.scrollToRow(selectrow);
                });
            }
        }
    },
    methods: {
        InitPageData() {
            this.ShowMain();
        },
        ShowMain() {
            this.loading = true;
            this.$tool
                .request({
                    url: "MNG/MNG2/MNG238",
                    method: "post",
                    data: {
                        action: "query",
                    }
                })
                .then(res => {
                    this.FirstLoading = true;
                    if (!res.hasOwnProperty("errcode")) {
                        this.oneBarcode = res.oneBarcode!='1';
                        if (res.RData.Data) {
                            if (res.RData.Data.length) {
                                var cotaindata = res.RData.Data;
                                this.tableData = cotaindata;
                                this.tableTempData = cotaindata;
                                this.loading = false;
                            } else {
                                this.tableData = [];
                                this.loading = false;
                            }
                        } else {
                            this.tableData = [];
                            this.loading = false;
                        }
                        
                    }
                });
        },
        currentChangeEvent({ row }) {
            this.YGKindRight = row;
            this.DelYGKindName = row.name;
            this.tempRowIndex = this.$refs.xTable.getRowIndex(row);
            if (this.curtabindex == 1) {
                this.ShowReqItem();
            }
        },
        getButtonWidth() {
            if (this.$refs.buttondiv) {
                this.buttonwidth = this.$refs.buttondiv.offsetWidth + "px";
            }
        },
        rowClassName({ row, rowIndex }) {},
        handleTabClick(tab, event) {
            if (tab.label == "基本信息") {
                this.editvisible = true;
                this.recordvisible = false;
            }
            if (tab.label == "申请项目") {
                this.curtabindex = 1;
                this.editvisible = false;
                this.recordvisible = true;
                this.ShowReqItem();
            }
        },
        
        OpenDialog(flag) {
            if (flag == 1) {
                this.dialogTitle = "新增院感类别";
                this.actionflag = flag;
                this.YGKind = {  };
                this.dialogYGKindFormVisible = true;
                this.$nextTick(() => {
                    this.$refs.autofocus1.focus();
                });
            }
            if (flag == 2) {
                this.dialogTitle = "修改院感类别";
                this.actionflag = flag;
                this.ShowUpdate();
                if(this.YGKind.code){
                    this.dialogYGKindFormVisible = true;
                    this.$nextTick(() => {
                        this.$refs.autofocus1.focus();
                    });
                }
            }
            if (flag == 3) {
                if(!this.YGKindRight.code){
                    return;
                }
                this.actionflag = flag;
                this.tempRowIndex = this.$refs.xTable.getRowIndex(this.$refs.xTable.getCurrentRow());
                this.dialogVisible = true;
            }
        },
        CommitTips() {
            if (this.actionflag < 3) {
                if (this.YGKind.code != "" && this.YGKind.name != "") {
                    this.SaveMain(this.actionflag);
                } else {
                    this.$message("院感类别名称和院感项目代码不能为空!");
                }
            } else {
                this.SaveMain(this.actionflag);
            }
        },
        CancelTips() {
            if (this.actionflag < 3) {
                this.dialogYGKindFormVisible = false;
            } else {
                this.dialogVisible = false;
            }
        },
        SaveMain(flag) {
            this.AddArray = "";
            var savedata = this.YGKind;
            if (flag == 1) {
                this.AddArray = savedata.code;
            }
            if (flag == 3) savedata.code = this.YGKindRight.code;
            this.$tool
                .request({
                    url: "MNG/MNG2/MNG238",
                    method: "post",
                    data: {
                        action: "save",
                        saveinfo: savedata,
                        oldinfo: this.OldYGKind,
                        utype: flag
                    }
                })
                .then(res => {
                    if (res.errcode == 1) {
                        this.$message({
                            message: "保存成功",
                            type: "success"
                        });
                        this.ShowMain();
                        this.$nextTick(() => {
                            switch (this.curtabindex) {
                                case 1:
                                    this.ShowReqItem();
                                    break;
                            }
                        });
                        if(flag!=1){
                            this.dialogYGKindFormVisible = false;
                        }else{
                            this.YGKind = {};
                            this.$refs.autofocus1.focus();
                        }
                        
                        this.dialogVisible = false;
                    } else {
                        this.$message.error("保存失败:" + res.errmsg);
                    }
                });
        },
        ShowUpdate() {
            this.$tool
                .request({
                    url: "MNG/MNG2/MNG238",
                    method: "post",
                    data: {
                        action: "queryforupdate",
                        code: this.YGKindRight.code
                    }
                })
                .then(res => {
                    if (res.Data.length) {
                        var reqdata = res.Data[0];
                        this.YGKind = reqdata;
                        this.OldYGKind = res.oldData[0];
                    }
                });
        },
        ShowReqItem() {
            this.loadingReqItem = true;
            this.$tool
                .request({
                    url: "MNG/MNG2/MNG238",
                    method: "post",
                    data: {
                        action: "reqitem",
                        code: this.YGKindRight.code
                    }
                })
                .then(res => {
                    if (res.Data.length) {
                        var cotaindata = res.Data;
                        this.tableDataReqItem = cotaindata;
                        this.loadingReqItem = false;
                    } else {
                        this.tableDataReqItem = [];
                        this.loadingReqItem = false;
                    }
                });
        },
        NameInput(value) {
            var pinyinres = this.$pinyin(value, {
                style: this.$pinyin.STYLE_FIRST_LETTER, // 首字母
                heteronym: true
            });
            var inputcode = "";
            for (var i = 0, len = pinyinres.length; i < len; i++) {
                if (pinyinres[i].length > 1) {
                    pinyinres[i].sort();
                }
                inputcode += pinyinres[i][0];
            }
            this.ReqItem.inputcode = inputcode.toLocaleUpperCase();
        },
        NameChange(value) {
            if (this.ReqItem.req_itemna == "") {
                if (value.length > 32) {
                    var na = value.slice(0, 31);
                    this.ReqItem.req_itemna = na;
                } else {
                    this.ReqItem.req_itemna = value;
                }
            }
        },
        rowClassName({ row, rowIndex }) {
            let isDirty = this.$refs.xTable.hasRowChange(row);
            if (isDirty) {
                return "row-modify";
            }
            if (this.$refs.xTable.hasRowInsert(row)) return "row-new";
        },
        //回车事件
        Funautofocus(element) {
            if (element == "autofocus0") {
                this.$refs.autofocus1.focus();
            } else if (element == "autofocus1") {
                this.$refs.autofocus2.focus();
            } else if (element == "autofocus2") {
                this.$refs.autofocus3.$refs.ddlmainSelect.focus();
            } else if (element == "autofocus3") {
                this.$refs.autofocus4.focus();
            } else if (element == "autofocus4") {
                this.$refs.autofocus5.focus();
            } else if (element == "autofocus5") {
                this.$refs.autofocus6.focus();
            } else if (element == "autofocus6") {
                this.$refs.autofocus7.focus();
            } else if (element == "autofocus7") {
                this.$refs.autofocus8.focus();
            } else if (element == "autofocus8") {
                this.$refs.autofocus9.focus();
            } else if (element == "rautofocus1") {
                this.$refs.rautofocus2.focus();
            } else if (element == "rautofocus2") {
                this.$refs.rautofocus3.focus();
            } else if (element == "rautofocus3") {
                //this.$refs.rautofocus3.focus();
                this.SaveReqMain(this.reqItemactionflag)
            } 
        },
        currentReqItemChangeEvent({ row }) {
            this.ReqItemRow = row;
            this.DelReqItemName = row.req_itemname;
            this.tempReqItemRowIndex = this.$refs.xTable2.getRowIndex(row);
        },
        OpenReqItemDialog(flag) {
            
            if (flag == 1) {
                if(!this.YGKindRight.code){
                    this.$message("请新增院感分类后再新增院感申请项目!");
                    return;
                }
                this.dialogReqItemTitle = "新增申请项目";
                this.reqItemactionflag = flag;
                this.ReqItem = {  };
                this.dialogFormVisible = true;
                this.$nextTick(() => {
                    this.$refs.rautofocus1.focus();
                });
            }
            if (flag == 2) {
                if(!this.YGKindRight.code){
                    return;
                }

                if(!this.ReqItemRow.req_itemcode){
                    this.$message("请选择需要修改的院感申请项目!");
                    return;
                }

                this.dialogReqItemTitle = "修改申请项目";
                this.reqItemactionflag = flag;
                this.ShowReqItemUpdate();
                this.dialogFormVisible = true;
                this.$nextTick(() => {
                    this.$refs.rautofocus1.focus();
                });
            }
            if (flag == 3) {
                if(!this.YGKindRight.code){
                    return;
                }

                if(!this.ReqItemRow.req_itemcode){
                    this.$message("请选择需要删除的院感申请项目!");
                    return;
                }
                this.reqItemactionflag = flag;
                this.tempReqItemRowIndex = this.$refs.xTable2.getRowIndex(this.$refs.xTable2.getCurrentRow());
                this.dialogReqItemVisible = true;
            }
        },
        ShowReqItemUpdate() {
            this.$tool
                .request({
                    url: "MNG/MNG2/MNG238",
                    method: "post",
                    data: {
                        action: "queryreqitemforupdate",
                        req_itemcode: this.ReqItemRow.req_itemcode
                    }
                })
                .then(res => {
                    if (res.Data.length) {
                        var reqdata = res.Data[0];
                        this.ReqItem = reqdata;
                        this.OldReqItem = res.oldData[0];
                    }
                });
        },
        CommitReqItemTips() {
            if (this.reqItemactionflag < 3) {
                if (this.ReqItem.req_itemcode != "" && this.ReqItem.req_itemname != "") {
                    this.SaveReqMain(this.reqItemactionflag);
                } else {
                    this.$message("申请项目名称和申请项目代码不能为空!");
                }
            }else{
                this.SaveReqMain(this.reqItemactionflag);
            }
        },
        CancelReqItemTips() {
            if (this.reqItemactionflag < 3) {
                this.dialogFormVisible = false;
            } else {
                this.dialogReqItemVisible = false;
            }
        },
        SaveReqMain(flag) {
            let that = this;
            var savedata = this.ReqItem;
            if (flag == 3) savedata.req_itemcode = this.ReqItemRow.req_itemcode;
            this.$tool
                .request({
                    url: "MNG/MNG2/MNG238",
                    method: "post",
                    data: {
                        action: "savereqitem",
                        saveinfo: savedata,
                        kind: this.YGKindRight.code,
                        oldinfo: this.OldReqItem,
                        utype: flag
                    }
                })
                .then(res => {
                    if (res.errcode == 1) {
                        this.$message({
                            message: "保存成功",
                            type: "success"
                        });
                        this.ShowReqItem();
                        if(flag != 1){
                            this.dialogFormVisible = false;
                        }
                        else{
                            that.ReqItem = {};
                            this.$nextTick(() => {
                                that.$refs.rautofocus1.focus();
                            });
                        }
                        this.dialogReqItemVisible = false;
                    } else {
                        this.$message.error("保存失败:" + res.errmsg);
                    }
                });
        },
    }
};
</script>

<style scoped>
/deep/.el-button--primary {
    color: black;
}
/deep/.vxe-input--wrapper .vxe-input {
    height: auto;
    width: 200px;
    border-radius: 0px;
}
/deep/.el-button--default.btn-custom-cancel {
    float: right !important;
    margin-left: 10px;
}
/deep/.el-input.is-disabled .el-input__inner {
    background-color: #f5f7fa;
    /* border-color: #E4E7ED; */
    color: #000000;
    cursor: not-allowed;
}
.pagetop {
    left: 0;
    right: 0;
    height: 35px;
    line-height: 35px;
    display: -webkit-box;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenter {
    position: absolute;
    top: 38px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    position: absolute;
    height: 100%;
    right: 805px;
    left: 0;
}

.middle-right {
    background-color: chartreuse;
    position: absolute;
    top: 0;
    bottom: 2px;
    width: 800px;
    right: 0px;
}

table tr td:nth-child(odd) {
    text-align: right;
    white-space: nowrap;
}
table tr td:nth-child(even) {
    text-align: left;
}
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}
/deep/.el-checkbox__inner::after {
    border: 2px solid #000000 !important;
    box-sizing: content-box;
    content: "";
    border-left: 0 !important;
    border-top: 0 !important;
    height: 7px;
    left: 4px;
    position: absolute;
    top: 1px;
    transform: rotate(45deg) scaleY(0);
    width: 3px;
    transition: transform 0.15s ease-in 0.05s;
    transform-origin: center;
}
/deep/.el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #000000;
    cursor: not-allowed;
}
/deep/ .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
    background-color: #ffffff !important;
}
/deep/ tr.vxe-body--row.row-modify {
    color: blue !important;
}
/deep/ tr.vxe-body--row.row-new {
    color: red !important;
}
.top-button {
    right: 5px;
    position: absolute;
    top: 5px;
    display: flex;
    align-items: center;
}
.top-title {
    margin: 0 3px 0 20px;
    font-size: 12px;
}
</style>